from pprint import  pprint
classes = [
    {"name": "name_1", "age": 25, "grade": "A"},
    {"name": "name_2", "age": 3, "grade": "C"},
    {"name": "name_4", "age": 15, "grade": "B"},
    {"name": "name_3", "age": 14, "grade": "D"},
    {"name": "name_5", "age": 13, "grade": "B"},
    {"name": "name_6", "age": 4, "grade": "B"},
    {"name": "name_7", "age": 5, "grade": "A"},
    {"name": "name_8", "age": 88, "grade": "D"},
]

#通过filter语句来筛选出Grade为A的同学
f = filter(lambda x: x.get("grade") == "A", classes)
print("grade为A的同学有：")
pprint(list(f))


#通过map函数将上述同学的age + 1(对原数据结构有影响，尽量不要用lambda)
def add(d):
    d["age"] += 1

m = map(add, classes)
list(m)
print("改变年龄之后：")
pprint(classes)


#使用递归函数重构菲波那切函数
def fibo(n):
    if n <= 1:
        return n
    else:
        return fibo(n - 1) + fibo(n - 2)
for mm in range(1, 20):
    print(fibo(mm), end=",")

